package main

import "fmt"

type Queue struct {
	container []int
	front     int
	rear      int
	size      int
}

func NewQueue(k int) *Queue {
	return &Queue{
		make([]int, k),
		0,
		0,
		0,
	}
}

func (q *Queue) EnQueue(value int) bool {
	if q.container == nil || q.IsFull() {
		return false
	}
	q.container[q.rear%len(q.container)] = value
	q.rear = q.rear%len(q.container) + 1
	q.size++
	return true
}

func (q *Queue) Dequeue() (bool, int) {
	if q.container == nil || q.IsEmpty() {
		return false, 0
	} else {
		ret := q.container[q.front%len(q.container)]
		q.front = q.front%len(q.container) + 1
		q.size--
		return true, ret
	}
}

func (q *Queue) IsEmpty() bool {
	return q.size == 0
}

func (q *Queue) IsFull() bool {
	return q.size == len(q.container)
}

func main() {
	queue := NewQueue(5)
	for i := 0; i < 3; i++ {
		for j := 0; j < 5; j++ {
			queue.EnQueue(j)
		}
		for k := 0; k < 3; k++ {
			fmt.Println(queue.Dequeue())
		}
	}

}
